package org.programmers.anonymous.fightrobots.model;

import org.apache.commons.lang.builder.HashCodeBuilder;



public class Deffense implements IDeffense, Comparable<Deffense>, Cloneable 
{
	protected int idDeffense;
	protected String name;
	protected int power;
	protected int hits;
	
	public Deffense(){
		this.setIdDeffense(-99);
		this.setName("Iron Shield");
		this.setPower(15);
		this.setHits(10);
	}
	
	@Override
	public int getIdDeffense() {
		return this.idDeffense;
	}

	@Override
	public void setIdDeffense(int idD) {
		this.idDeffense = idD;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String n) {
		name = n;
	}

	@Override
	public int getPower() {
		return power;
	}

	@Override
	public void setPower(int p) {
		power = p;
	}
	
	public int getHits() {
		return hits;
	}

	public void setHits(int hits) {
		this.hits = hits;
	}
	
	@Override
	public int compareTo(Deffense d) 
	{
		if (this.getIdDeffense() == d.getIdDeffense() 
			&& this.getName().compareTo(d.getName()) == 0 
			&& this.getPower() == d.getPower())
		{
			return 0;
		}	
		else 
		{
			return this.getName().compareTo(d.getName());
		}
	}
	
	@Override
	public Deffense clone()
	{
		Deffense result = new Deffense();
		result.setName(new String(this.getName()));
		result.setPower(this.getPower());
		return result;
	}
	
	@Override
	 public boolean equals(Object obj)
	{
		if (obj == null)
            return false;
        if (obj == this)
            return true;
        if (!(obj instanceof IDeffense))
            return false;

		IDeffense d = (IDeffense) obj;
		
		if(this.getName().equalsIgnoreCase(d.getName()))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	
	@Override
	public String toString()
	{
		StringBuffer strBuff = new StringBuffer();
		strBuff.append("{");
		strBuff.append("idDeffense:");
		strBuff.append(idDeffense);
		strBuff.append(",name:");
		strBuff.append(name);
		strBuff.append(",power:");
		strBuff.append(power);
		strBuff.append(",hits:");
		strBuff.append(hits);
		strBuff.append("}");
		
		return strBuff.toString();
	}
	
	@Override
	 public int hashCode() {
	        return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
	            // if deriving: appendSuper(super.hashCode()).
	            append(name).
	            toHashCode();
	}
	
}
